﻿using System;
using System.Threading.Tasks;
using ReactiveUI;

namespace MilkTeaMachine.OfflineClient.ViewModels;

public class HourGlassViewModel : ViewModelBase, IRoutableViewModel
{
    public delegate Task DoItAsyncDelegate();

    public HourGlassViewModel(IScreen hostScreen, DoItAsyncDelegate doItAsync)
    {
        HostScreen = hostScreen;
        _ = ReturnToScanOrderPageAsync(doItAsync);
    }

    private async Task ReturnToScanOrderPageAsync(DoItAsyncDelegate doItAsync)
    {
        await doItAsync().ConfigureAwait(true);
        HostScreen.Router.NavigateAndReset.Execute(new AutoRunningScanOrderViewModel(HostScreen));
    }

    public string? UrlPathSegment { get; } = nameof(HourGlassViewModel);
    public IScreen HostScreen { get; }
}